﻿<!DOCTYPE HTML>
<html lang="zh">
<head>
<title>Break - 语法 &amp; 使用 | AutoHotkey v2</title>
<meta name="description" content="The Break statement exits (terminates) any type of loop statement." />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
<script type="text/javascript">$(function(){0<=window.navigator.userAgent.toLowerCase().indexOf("ucbrowser")&&CaoNiMaDeUc()})</script>
</head>
<body>

<h1>Break</h1>
<p>退出(终止) 任意类型的<a href="../Language.htm#loop-statement">循环语句</a>.</p>
<pre class="Syntax"><span class="func">Break</span> <span class="optional">LoopLabel</span></pre>

<h2 id="Parameters">参数</h2>
<dl>
  <dt>LoopLabel</dt>
  <dd>
    <p><em>LoopLabel</em> 标识此语句应该应用于哪层循环; 可通过<a href="../misc/Labels.htm">标签名称</a>或数字嵌套层级来实现. 如果省略或为 1, 则此语句适用于包含它的最内层循环. 如果指定了<a href="../misc/Labels.htm">标签</a>, 标签必须直接指向<a href="../Language.htm#loop-statement">循环语句</a>.</p>
    <p><em>LoopLabel</em> 必须为常量值 - 不支持变量和表达式, 但括号中的单个原义数字或用圆括号括起来的字符串除外. 例如: <code>break("outer")</code></p>
  </dd>
</dl>

<h2 id="Remarks">备注</h2>
<p>鼓励使用 Break 和 <a href="Continue.htm">Continue</a> 代替 <a href="Goto.htm">Goto</a>, 因为它们通常让脚本更容易阅读和维护.</p>
<h2 id="Related">相关</h2>
<p><a href="Continue.htm">Continue</a>, <a href="Loop.htm">Loop</a>, <a href="While.htm">While-loop</a>, <a href="For.htm">For-loop</a>, <a href="Block.htm">Blocks</a>, <a href="../misc/Labels.htm">Labels</a></p>

<h2 id="Examples">示例</h2>
<div class="ex" id="ExBasic">
<p><a href="#ExBasic">#1</a></p>
<pre>Loop
{
    <em>; ...</em>
    if (var &gt; 25)
        break
    <em>; ...</em>
    if (var &lt;= 5)
        continue
}</pre>
</div>

<div class="ex" id="ExBreakOuter">
<p><a href="#ExBreakOuter">#2</a>: 从嵌套循环中退出 outer(外部) 循环.</p>
<pre>outer:
Loop 3
{
    x := A_Index
    Loop 3
    {
        if (x*A_Index = 6)
            break outer  <em>; 等同于 <b>break 2</b> 或 <b>goto break_outer</b>.</em>
        MsgBox x "," A_Index
    }
}
break_outer: <em>; 用于 goto.</em>
</pre>
</div>

</body>
</html>